function addteachertitle() {
    $.get("/titleQuestion/findTitle", {
        question_type: $("#question_type").val(),
        /*grade: $("#grade").val(),*/
        question_direction: $("#question_direction").val(),
        /*            title: $("#title").val(),
                    daan: $("#daan").val()*/
    }, function (data) {
        console.log(data);
        // alert(data.result);
        var html = '';
        for (let i = 0; i < data.result.length; i++) {
            if ((i + 2) % 2 == 0) {
                html += '<tr class="active">\n' +
                    '                        <td><input type="checkbox" class="select" name="titleId" value="' + data.result[i].question_id + '"></td>\n' +
                    '                        <td>' + i + '</td>\n' +
                    '                        <td>' + data.result[i].question_subject + '</td>\n' +
                    '                        <td>' + data.result[i].question_type + '</td>\n' +
                    '                        <td>' + data.result[i].question_option + '</td>\n' +
                    '                        <td>' + data.result[i].question_answer + '</td>\n' +
                    '                        <td>' + data.result[i].question_level + '</td>\n' +
                    '                        <td>' + data.result[i].question_direction + '</td></tr>';
            } else {
                html += '<tr class="success">\n' +
                    '                    <td><input type="checkbox" class="select" name="titleId" value="' + data.result[i].question_id + '"></td>\n' +
                    '                    <td>' + i + '</td>\n' +
                    '                    <td>' + data.result[i].question_subject + '</td>\n' +
                    '                    <td>' + data.result[i].question_type + '</td></td>\n' +
                    '                    <td>' + data.result[i].question_option + '</t</td>\n' +
                    '                    <td>' + data.result[i].question_answer + '</t</td>\n' +
                    '                    <td>' + data.result[i].question_level + '</td</td>\n' +
                    '                    <td>' + data.result[i].question_direction + '</td></tr>';
            }
        }
        $("#findalltitle").html(html);
    }, "json");
}

function selectall(obj) {
    $(".select").prop("checked", obj.checked)
}

var sumTitle;
window.onload = function () {
    //给添加按钮添加绑定事件
    document.getElementById("addtitleid").onclick = function () {
        //标段提交
        alert("确定，需要添加？");
        document.getElementById("checkboxform").submit();
        var length = $("input[type='checkbox']:checked").length;
        sumTitle += length;
        var type = $("#question_type").val();
        modeltype(type, length);
        alert("添加成功，即将跳转");
        tiaozhuan();
    }
}
localStorage.setItem("sumTitle", sumTitle);

function tiaozhuan() {
    window.location.href = "testpaper.html";
}

function modeltype(model, len) {
    if (model == '单选题') {
        localStorage.setItem("choose_number", len);
    } else if (model == '填空题') {
        localStorage.setItem("completion_num", len);
    } else if (model == '判断题') {
        localStorage.setItem("recognized_num", len);
    }
}

$(document).ready(function () {
    getSubject("SUBJECT");
    getTitleModel("QUESTIONTYPE");
});

//获取科目
function getSubject(obj) {
    $.get('/testPaper/getByModel', {select_type: obj}, function (data) {
        console.log(data.result);
        html = '';
        for (let i = 0; i < data.result.length; i++) {
            html += '<option>' + data.result[i].select_name + '<option>';
            console.log(data.result[i].select_name);
        }
        console.log(html);
        $("#question_direction").html(html);
    }, 'json');
}

//获取题型
function getTitleModel(obj) {
    $.get('/testPaper/getByModel', {select_type: obj}, function (data) {
        console.log(data.result);
        html = '';
        for (let i = 0; i < data.result.length; i++) {
            html += '<option>' + data.result[i].select_name + '<option>';
            console.log(data.result[i].select_name);
        }
        console.log(html);
        $("#question_type").html(html);
    }, 'json');
}